package com.cpr.core.rabbitmq.springctl.xml;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Chen Panrui
 * created at 2022/3/15 23:12
 */
public class ConsumerGetApp {
    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-rabbit.xml");
        RabbitTemplate template = context.getBean(RabbitTemplate.class);

        // 拉取消息的模式 get
        Message message = template.receive("queue.spring.q1");
        assert message != null;
        System.out.println(new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
    }
}
